// stores/counter.js
import { defineStore } from 'pinia'

export const useUserStore = defineStore('UserInfo', {
  state: () => ({ UserId: '', UserName: '', UserPwd: '' }),
  actions: {
    // 重置store状态
    resetStore() {
        this.UserId = ''
        this.UserName = ''
        this.UserPwd = ''
      },
      // 设置用户信息
      setUserInfo(userId, userName, userPwd) {
        this.UserId = userId
        this.UserName = userName
        this.UserPwd = userPwd
      },
      setUserName(userName){
        this.UserName = userName
      },
      // 用户退出
      logout() {
        this.resetStore()
    }
  
  },
  persist: {
    enabled: true, // 启用持久化
    storage: localStorage, // 指定存储方式，默认为 localStorage
    paths: ['UserId','UserName','UserPwd'], // 指定需要持久化的 state 属性
  }
})